Private ["_dir","_speed","_vehicle","_vel","_id","_countdown","_launch","_abort","_launchcount"];

_vehicle = _this select 0;
_id = _this select 2;
_countdown = 5;
_launchcount = 20;
_speed = 2.5;
_abort = 0;
_vel = velocity _vehicle;
_dir = direction _vehicle;
_launch = _launchcount;

//_vehicle removeAction _id;

while {(_countdown > 0) AND (_abort == 0)} do
	{
		hintSilent format["Launching in %1 seconds.",_countdown];
		sleep 1;
		if ((fuel _vehicle == 0) OR (speed _vehicle > 4) OR !(canmove _vehicle)) then
			{_abort = 1;};
		_countdown = _countdown - 1;
	};
	
if (_abort == 0) then {hintSilent "Launch in progress.";};

while {(_launch > 0) AND (_abort == 0)} do
	{
		_vel = velocity _vehicle;
		_dir = direction _vehicle;
		_vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+(cos _dir*_speed),(_vel select 2)];
		_launch = _launch - 1;
		sleep (1/_launchcount);
	};
	
if (_abort == 0) then
	{sleep 2;
	hintSilent "Launch complete.";}
	else
	{hintSilent "Launch aborted.";};
	
sleep 3;
hint "";

//_vehicle addAction ["<t color=""#FF0000"">" + "Catapult Launch","Action_CatapultLaunch.sqf", [], 0, false, true, "", "driver _target == _this && alive _target && speed _target < 4 && speed _target > -4 && getPos _target select 2 < 4"];